Example:
請解決General case:
Notes
o -> 喝爆, x -> 沒喝
Bucket 1 2 3 4
Pig1 o o x x
Pig2 o x o x
o -> 喝爆, x -> 沒喝
Bucket 1 2 3 4 5 6 7 8 9
Pig1 o o o x x x x x x
Pig2 o x x o o x x x x
buckets = (T+1)^p
p >= log(T+1, buckets)
class Solution {
public:
int poorPigs(int buckets, int minutesToDie, int minutesToTest) {
int T = minutesToTest/minutesToDie;
return static_cast<int>(ceil(log(buckets) / (log(T + 1))));
}
};